package com.zy.chapter8

/**
 * @author: zhaoyi
 * @create: 2020-09-14 22:55
 * @description: ${description}
 **/
class HashCodeEq {

  var age: Int = _
  var name: String = _


  def this(age: Int, name: String) {
    this()
    this.age = age
    this.name = name
  }

  //.##  null安全版本的hashCode
  override def hashCode(): Int = (age, name).##

  override def equals(obj: Any): Boolean = {
    obj match {
      case e: HashCodeEq => e.name.eq(this.name) && e.age == this.age
      case _ => false
    }
  }
}
